﻿using CatUtils.Utils.Currency;
using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Currency.TextUtils;
using CatUtils.Utils.SpecialUtils.Html;
using System;
using System.Collections.Generic;

namespace SinaImgUpload.SainTool.LocalTool
{
    internal class ClearWithCount
    {
        /// <summary>
        /// 批量清理数量不足预设值
        /// </summary>
        /// <param name="FloderPath"></param>
        internal void ClearXmlWithFloder(string FloderPath, string MinCountText)
        {
            List<string> FoloderList = FloderNameHelper.GetFullFileNameList(FloderPath, "*.lst");
            foreach (string line in FoloderList)
            {
                Console.WriteLine(line);
                ClearXmlWithFile(line, MinCountText);
            }
        }

        /// <summary>
        /// 单独文件处理
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="MinCountText"></param>
        public void ClearXmlWithFile(string FilePath, string MinCountText)
        {
            SingleFile(FilePath, TextHelper.StringToInt(MinCountText));
        }

        /// <summary>
        /// 单独文件处理
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="MinCount"></param>
        public void SingleFile(string FilePath, int MinCount)
        {
            List<String> ImgList = HtmlHelper.GetHtmlValueList(FileHelper.ReadAllText(FilePath), "//bed");

            if (ImgList.Count < MinCount)
            {
                Console.WriteLine("数量{0}不足预设{1}", ImgList.Count, MinCount);
                string NewFilePath = FileNameHelper.CreateFileNameWithChildFloder(FilePath, string.Format("数量低于{0}", MinCount));
                FileHelper.FileMove(FilePath, NewFilePath);
            }
        }
    }
}